import request from "@/utils/request";

/**
 * 获取角色列表
 * @param {Object} query 查询参数根据接口来进行
 * @returns Promise
 */
export const getRoleListAPI = (query) => {
  return request({
    method: "get",
    url: "/sys/role",
    params: query,
  });
};
/**
 * 删除角色
 * @param {String} roleId 角色id
 * @returns Promise
 */
export const delRoleAPI = (roleId) => {
  return request({
    url: `/sys/role/${roleId}`,
    method: "delete",
  });
};
/**
 * 新增角色
 * @param {Object} roleForm 角色表单
 * @returns Promise
 */
export const addRoleAPI = (roleForm) => {
  return request({
    url: "/sys/role",
    method: "post",
    data: roleForm,
  });
};
/**
 * 根据 id 获取角色详情, 用于回显
 * @param {string} roleId 角色id
 * @returns promise
 */
export const getRoleDetailAPI = (roleId) => {
  return request({
    method: "get",
    url: `/sys/role/${roleId}`,
  });
};
/**
 * 编辑角色
 * @param {string} roleForm 角色表单
 * @returns promise
 */
export const editRoleAPI = (roleForm) => {
  return request({
    method: "put",
    url: `/sys/role/${roleForm.id}`,
    data: roleForm,
  });
};
/**
 *获取公司详情
 * @param {string} companyId 公司id
 * @returns promise
 */
export const getCompanyDetailAPI = (companyId) => {
  return request({
    method: "get",
    url: `company/${companyId}`,
  });
};
/**
 *给角色分配权限
 * @param {STring} id 角色id
 * @param {Array} permIds 权限数组
 * @returns Promise
 */
export const assignPermAPI = (id, permIds) => {
  return request({
    method: "put",
    url: "/sys/role/assignPrem",
    data: {
      id,
      permIds,
    },
  });
};
